<template>
  <div class="more-app">
    <m-top-bar ref="topbar" :tableId="tableId"/>

    <more-tree-table
      ref="treeTable"
      :getDiagramFilter='getDiagramFilter'
      :visible='visible'
      :MatrixFilter="matrixFilter"></more-tree-table>

  </div>

</template>

<script>
import Vue from 'vue';
import MoreTreeTable from "./TreeTableComponents/MoreTreeTable";
import TopBar from "./TreeTableComponents/topBar";
import treeUtil from '../ModelTree/treeUtil';
Vue.component('more-tree-table', MoreTreeTable);
export default {
  name: 'dependency-matrix',
  components: {
    /* MoreTreeTable, */
    'm-top-bar': TopBar
  },
  props: {
    visible: { type: Boolean },
    tableId: String
  },
  data() {
    console.log('dependency-matrix created');
    return {
      matrixFilter: {}
    };
  },
  computed: {
    getDependencies(){
      let allrelations = [['抽象', 'Abstraction'],
        ['聚合关系', 'Aggregation'],
        ['分配', 'Allocate'],
        ['注释线', 'Anchor'],
        ['关联关系', 'Association'],
        ['绑定连接器', 'BindingConnector'],
        ['调用消息', 'CallMessage'],
        ['组合关系', 'Composition'],
        ['连接器', 'Connector'],
        ['包含', 'Containment'],
        ['控制流', 'ControlFlow'],
        ['复制', 'Copy'],
        ['创建消息', 'CreateMessage'],
        ['删除消息', 'DeleteMessage'],
        ['依赖', 'Dependency'],
        ['派生需求', 'DeriveReqt'],
        ['定向聚合', 'DirectedAggregation'],
        ['定向关联', 'DirectedAssociation'],
        ['定向组合', 'DirectedComposition'],
        ['时间段约束', 'DurationConstraint'],
        ['元素导入', 'ElementImport'],
        ['异常处理器', 'ExceptionHandler'],
        ['扩展关系', 'Extend'],
        ['找回的消息', 'FoundMessage'],
        ['泛化关系', 'Generalization'],
        ['包含关系', 'Include'],
        //// ['信息流', 'InformationFlow'],
        ['实例连接', 'Link'],
        ['丢失的消息', 'LostMessage'],
        ['消息', 'Message'],
        ['给自己的消息', 'MessageToSelf'],
        ['对象流', 'ObjectFlow'],
        ['包导入', 'PackageImport'],
        ['实现', 'Realization'],
        ['精化', 'Refine'],
        ['回复消息', 'ReplyMessage'],
        ['满足', 'Satisfy'],
        ['发送消息', 'SendMessage'],
        ['状态常量', 'StateInvariant'],
        ['时间点约束', 'TimeConstraint'],
        ['追踪', 'Trace'],
        ['转换', 'Transition'],
        ['使用', 'Usage'],
        ['验证', 'Verify'],
        ['递归消息', 'RecursiveMessage']];
      let typelist = treeUtil.buildMatrixTypeList();
      typelist = typelist[0].children;
      //// console.log({ typelist })
      let reqType =  typelist.filter(x => x.value == 'Requirement');//// [{ title: '需求', value: 'Requirement', key: '0-170' }];
      //// console.log({ reqType });
      let alocReqType = typelist.filter(x => x.value == 'Block');//// [{ title: '模块', value: 'Block', key: '0-70' }];
      let depMap = { SysMLDeriveRequirementMatrix: { dependency: ['DeriveReqt'], cellHeadType: reqType },
        SysMLRefineRequirementMatrix: { dependency: ['Refine'], cellHeadType: reqType },
        SysMLSatisfyRequirementMatrix: { dependency: ['Satisfy'], cellHeadType: reqType }
        , SysMLAllocationMatrix: { dependency: ['Allocate'], cellHeadType: alocReqType }

        , SysMLVerifyRequirementMatrix: { dependency: ['Verify'], cellHeadType: reqType },

        SysMLDependencyMatrix: { dependency: [], cellHeadType: [] }
      };
      let matrixType = app.activeGraphTab.graphNode.umlDiagramFrame.umlDiagramBridge.getUMLDiagram().getClassName();     
      let dep = depMap[matrixType];
      let relation = allrelations.map((x, y) => {
        return {
          key: String(y),
          name: x[0],
          isVisible: true,
          icon: x[1],
          style: { color: '#5AD8A6' },
        };
      });

      relation = relation.map(x => {
        let visible = false;
        if (['SysMLDependencyMatrix'].includes(matrixType)){
          visible = false;
        } else {
          if (dep.dependency.includes(x.icon)){
            visible = true;
          }
        }

        return Object.assign(x, { isVisible: visible });
      });

      dep.dependency = relation;
      Object.assign(dep, { diagramType: matrixType });
      console.log('关系的类型', dep);
      return dep;
    },

  },
  watch: {},
  created(){ this.matrixFilter = this.initMatrixFilter(); },
  mounted(){

  },
  methods: {
    getDiagramFilter(){   
      let filter = app.activeGraphTab.graphNode.umlDiagramFrame.umlDiagramBridge.getUMLDiagram();
      return filter;
    },

    initMatrixFilter(){
      let enabledNode = app.sysmlModel.children.filter(x => treeUtil.isProfile(x) === false);
      //// console.log(88888);
      //// console.log({ enabledNode });
      let defaultFilter = { realationSelectionEnabled: this.getDependencies.diagramType === 'SysMLDependencyMatrix', removedNodes: [], emptyFilterType: 0, swapStatus: false, dicrection: 'both', dependencyCriteria: this.getDependencies.dependency,
      //// 初始选中的不包含树上sysml节点的内容
        colScope: [app.selectedElement.id], rowScope: [app.selectedElement.id], colType: this.getDependencies.cellHeadType,
        rowType: this.getDependencies.cellHeadType };
      let filter = this.getDiagramFilter();
      if (filter && filter['getMatrixStorage']){
        let currentFilter = filter.getMatrixStorage();
        if (currentFilter){
          currentFilter = JSON.parse(currentFilter);
          if (currentFilter['rowScope']){
            console.log(currentFilter, '还原模型信息--');
            return currentFilter;
          }
          
        }
      } else {
        console.error('异常调用');
      }

      return defaultFilter;
    }

  }
};
</script>

<style>
.more-app{
  /* width: calc(100vw - 140px); */
  width: 100%;
  height: 100%;
  display:flex;
  flex-direction: column;
  
}
</style>
